import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'index',
      component: () => import('../views/home/index.vue'),
      children: [
        {
          path: "/home",
          name: "home",
          component: () => import('../views/home/child/home.vue'),
        },
        {
          path: '/list',
          name: 'list',
          component: () => import('../views/home/child/list.vue'),

        },
        {
          path: '/car',
          name: 'car',
          component: () => import('../views/home/child//car.vue')
        },
        {
          path: '/my',
          name: 'my',
          component: () => import('../views/home/child//my.vue')
        },

      ]
    },
    {
      path: "/item/:id",
      component: () => import('../views/home/child/Item.vue'),
    },

    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/login.vue')
    },
    {
      path: '/regest',
      name: 'regext',
      component: () => import('../views/login/regest.vue')
    },
  ]
})
// router.beforeEach((to, from, next) => {
//   let token = localStorage.getItem('token')
//   if (!token && to.name !== 'login') {
//     next({ path: "/login" } && { path: "/regest" })
//   } else {
//     next()
//   }
// })
export default router
